
layui.config({
    version:'1510164124181'
}).use(['form','laydate', 'laypage', 'layer', 'element'],function(){
    form = layui.form;
    layer = layui.layer;
    $ = layui.jquery;
    laydate = layui.laydate;//日期
    laypage = layui.laypage;//分页
    element = layui.element; //元素操作
    initData();

});

function SearchInfo(){
    pageNo = 1
    initData()
}
function onloadInfo(){
    initData()
}
function initData(){
    let state = $('#activitiesState').find('option:selected').val();
    $.ajax({
        url: httpurl+"/callSpellEntity",
        cache: false,
        data: {
            "page":pageNo,
            "pagesize":pageRecords,
            "state":state==-1?'':state
        },
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        success: function(data){
            if(data.rtnCode==200){
                let dataList=data.data;
                HandleData(dataList);
            }else{
                totalRecords =0;
                let data_list= '<tr>'
                    +'<td colspan="12" style="text-align:center;">暂无数据</td>'
                    +'</tr>';
                $("#tableInfo tbody").html(data_list);
                layer.closeAll();
                page();
            }
        }
    });
}

function HandleData(initdata){
    let data_list="";
    if(initdata.length>0){
        totalRecords =initdata[0].total;
        for(let i=0;i<initdata.length;i++){
            data_list+='<tr>'+
                            '<td><input type="checkbox" data-id="'+initdata[i].id+'" name="box" class="aceChild"/></td>' +
                            '<td class="width10"><img width="70%" src="'+visitimgurl+'/'+(initdata[i].productEntity==null?"":initdata[i].productEntity.headimg)+'"></>'+
                            '<th>'+(initdata[i].productEntity==null?"":initdata[i].productEntity.title)+'</th>'+
                            '<td>'+initdata[i].starttime+'</td>'+
                            '<td>'+initdata[i].endtime+'</td>'+
                            '<td>'+initdata[i].waittime+'</td>'+
                            '<td>'+initdata[i].num+'</td>'+
                            '<td>'+
                                '<a  href="addSpell.html?SpellId='+initdata[i].id+'">编辑</a>&nbsp;&nbsp;' +
                                '<a href="#" data-info="DeleSpellInfo" data-id="'+initdata[i].id+'"  onclick="DeleteInfo(this)">删除</a>' +
                            '</td>'+
                        '</tr>';
        }
    }else{
        totalRecords =0;
        data_list += '<tr>'
            +'<td colspan="12" style="text-align:center;">暂无数据</td>'
            +'</tr>';
    }
    $("#tableInfo tbody").html(data_list);
    layer.closeAll();
    page();
}

//分页
function page(){
    laypage.render({
        elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
        ,count:totalRecords //数据总数，从服务端得到
        ,curr: pageNo //获取起始页 location.hash.replace('#!fenye=', '')
        ,hash: 'fenye' //自定义hash值
        ,layout: ['count', 'prev', 'page', 'next', 'skip']
        ,limit:10
        ,jump: function(obj, first){
            //首次不执行
            if(!first){
                //	  console.log("当前页==="+obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                //	  console.log("每页显示条数==="+obj.limit); //得到每页显示的条数
                pageNo=obj.curr;
                pageRecords=obj.limit;
                initData();
            }
        }
    });
}

function search(){
    pageNo=1;
    initData();
}
